import {action, observable} from 'mobx';

class MobxData {
    // status 状态  prepare: 准备学习  learning: 学习中  complete: 完成学习
    @observable study: Array<Object> = [
        {
            id: 1,
            name: "React",
            status: "prepare",
        }
    ];
    // 添加
    @action addStudy = (name: string) => {
        this.study.push({
            id: this.study.map((item: any) => item.id).reduce((max, p) => Math.max(max, p), 0) + 1,
            name: name,
            status: "prepare",
        });
    }
    // 改变状态
    @action upStudy = (id: number, status: string) => {
        this.study = this.study.map((item: any) => {
            if (item.id === id) {
                return {
                    ...item,
                    status
                }
            } else {
                return item;
            }
        });
    }
    // 删除
    @action delStudy = (id: number) => {
        this.study = this.study.filter((item: any) => item.id !== id);
    }

    // 边界
    @observable boundary: Array<Object> = [];
    // 添加
    @action addBoundary = (data: Object) => {
        this.boundary.push(data);
    }
}


export default new MobxData()